<template>
	<view class="comb-container">
		<text class="comb-title">子组件B</text>
		<view class="comb-content">
			<text class="comb-label">CompA组件传来的值：</text>
			<text class="comb-value">{{ result }}</text>
		</view>
		<view class="comb-callback">
			<text class="comb-label">回传值：</text>
			<input 
				type="text" 
				v-model="callbackValue" 
				class="comb-input" 
				placeholder="请输入回传内容"
			/>
			<button @click="sendOutside()" size="mini" class="comb-btn">回传</button>
		</view>
	</view>
</template>

<script>
export default {
	name: "ComB",
	data() {
		return {
			result: '', // 新增：存储从ComA接收的值（原代码未定义）
			callbackValue: '' // 新增：存储回传输入值（原代码未定义）
		};
	},
	// 修正：created生命周期应放在methods外部（原代码嵌套错误）
	created() {
		uni.$on('getIntent', (msg) => {
			console.error("----CompB---gitIntent---->" + msg);
			this.result = msg;
		});
	},
	methods: {
		sendOutside() {
			console.warn("----ComB----sendOutside---->" + this.callbackValue);
			// 触发自定义事件，向父组件回传值
			this.$emit('callBackFun', this.callbackValue);
		}
	}
}
</script>

<style scoped>
.comb-container {
	padding: 20rpx;
	background-color: #fdf2f8;
	border-radius: 16rpx;
	margin: 20rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.comb-title {
	font-size: 32rpx;
	font-weight: 600;
	color: #2d3748;
	margin-bottom: 20rpx;
	display: block;
}
.comb-content {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	margin-bottom: 24rpx;
}
.comb-label {
	font-size: 28rpx;
	color: #4a5568;
	margin-right: 12rpx;
}
.comb-value {
	font-size: 28rpx;
	font-weight: bold;
	color: #9f7aea;
	padding: 8rpx 16rpx;
	background-color: #fff;
	border-radius: 8rpx;
	border: 1px solid #f3e8ff;
}
.comb-callback {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 12rpx;
}
.comb-input {
	flex: 1;
	height: 72rpx;
	padding: 0 16rpx;
	background-color: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 8rpx;
	font-size: 26rpx;
	color: #2d3748;
}
.comb-btn {
	height: 72rpx;
	font-size: 26rpx;
	background-color: #4299e1;
	color: #fff;
	border-radius: 8rpx;
}
</style>